package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250224075700CreateUsersTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250224075700CreateUsersTable) Signature() string {
	return "20250224075700_create_users_table"
}

// Up Run the migrations.
func (r *M20250224075700CreateUsersTable) Up() error {
	if !facades.Schema().HasTable("users") {
		return facades.Schema().Create("users", func(table schema.Blueprint) {
			table.ID()
			table.String("username")
			table.String("password")
			table.String("real_name")
			table.Date("birthday").Nullable()
			table.String("card_id").Nullable()
			table.String("mark").Nullable()
			table.UnsignedInteger("group_id").Nullable()
			table.String("nickname").Nullable()
			table.String("phone")
			table.String("add_ip").Nullable()
			table.DateTime("last_time").Nullable()
			table.Integer("now_money").Nullable()                                    //用户余额
			table.Integer("brokerage_money").Nullable().Default(0)                   //佣金金额
			table.Integer("integral").Nullable().Default(0)                          //用户积分
			table.Integer("exp").Nullable().Default(0)                               //用户经验
			table.Integer("sign_num").Nullable().Default(0)                          //签到次数
			table.SmallInteger("status").Default(1)                                  //用户状态
			table.Integer("level").Default(1)                                        //等级
			table.String("user_type").Default("wechat")                              //用户类型
			table.Integer("is_delivery").Nullable()                                  //是否送货员is_delivery
			table.Integer("pay_count").Nullable().Default(0)                         //购买次数
			table.String("address").Nullable().Default("")                           //用户地址
			table.Integer("admin_id").Nullable()                                     //作为管理员的id
			table.Enum("login_type", []any{"h5", "wechat", "routine"}).Default("h5") //登录类型
			table.String("avatar").Nullable()
			table.Integer("staff_id").Nullable()   //作为员工的id
			table.String("invite_code").Nullable() //邀请码
			table.Timestamps()
			table.SoftDeletes("deleted_at")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250224075700CreateUsersTable) Down() error {
	return facades.Schema().DropIfExists("users")
}
